<?php

$lines1 = file('./namelist/allchinese.idx', FILE_IGNORE_NEW_LINES);
$lines2 = file('./namelist/foreign.txt', FILE_IGNORE_NEW_LINES);
$lines3 = file('./namelist/dead.txt', FILE_IGNORE_NEW_LINES);

$db = new SQLite3('citizens.db');

$db->exec('BEGIN');

foreach($lines1 as $line) {
	$a = explode(',', $line);
	$id = $a[0];
	
	$query = "UPDATE users SET citizen=14 WHERE id=$id";
					
	$db->exec($query);
}

foreach($lines2 as $line) {
	$a = explode(',', $line);
	$id = $a[0];
	
	$query = "UPDATE users SET citizen=0 WHERE id=$id";
					
	$db->exec($query);
}

foreach($lines3 as $line) {
	$a = explode(',', $line);
	$id = $a[0];

	$query = "SELECT id FROM users WHERE id=$id";
					
	$result = $db->querySingle($query);
	
	if ($result != NULL) {
		echo "$line\r\n";
		$query = "UPDATE users SET citizen=0 WHERE id=$id";
		$db->exec($query);
	}
}

$db->exec('COMMIT');

?>